﻿namespace IBTrader.Modules.Log
{
    using NLog;
    using System;
    using System.Collections.Generic;
    using System.Linq;

    class LogTarget
    {
        public event EventHandler<LogArgs> Log;
        private static readonly List<LogTarget> instances = new List<LogTarget>();
        public LogTarget()
        {
            instances.Add(this);
        }
        public static void LogMethod(string level, string message, string callsite)
        {
            var e = new LogArgs { Level = LogLevel.FromString(level), Message = message, CallSite = callsite };
            instances.Where(i => i.Log != null).ToList().ForEach(i => i.Log(i, e));
        }
        public class LogArgs : EventArgs
        {
            public LogLevel Level { get; set; }
            public string Message { get; set; }
            public string CallSite { get; set; }
        }
    }
}